package com.businessportal.web.controllers.admin;

import com.businessportal.web.dataaccess.entities.Login;
import com.businessportal.web.dataaccess.services.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created by Vadim on 1/15/2015.
 */

@WebServlet(urlPatterns = "/securepages/address_deleter.do")
public class AddressDeleterController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        try
        {
            req.setCharacterEncoding("UTF-8");

            HttpSession session = req.getSession();
            Login user = (Login) session.getAttribute("user");

            String addressId = req.getParameter("addres_id");

            if(null != user && null != addressId && !addressId.isEmpty()){
                UserService.INSTANCE.RemoveAddress(user, Long.parseLong(addressId));
            }
        }
        catch(Exception e)
        {

        }

        resp.sendRedirect("/securepages/admin_portal.jsp");
    }
}
